<?php

namespace app\admin\service\common\token;

use think\facade\Config;
use app\admin\service\common\token\TokenServiceInterface;

class TokenServiceFactory
{
    public static function create(): TokenServiceInterface
    {
        // 获取配置文件中的存储类型设置
        $storageType = Config::get('rds.token_repo', 'cache');

        // 根据配置创建对应的存储仓库
        $repository = self::createTokenRepository($storageType);

        // 使用存储仓库初始化JWT令牌服务
        return new JwtTokenService($repository);
    }

    protected static function createTokenRepository(string $type): TokenRepositoryInterface
    {
        switch (strtolower($type)) {
            case 'db':
                return new DbTokenRepository();
            case 'cache':
            default:
                return new CacheTokenRepository();
        }
    }
}